import React, { Component } from "react";
import { Form, Modal, Button, Input, message } from "antd";

const layout = {
  labelCol: {
    span: 8,
  },
  wrapperCol: {
    span: 14,
  },
};
const tailLayout = {
  wrapperCol: {
    offset: 8,
    span: 14,
  },
};
export default class EditAdd extends Component {
  state = {
    submitLoading: false,
    showAdd: false,
  };
  addMachineClick = () => {
    this.setState({
      showAdd: true,
    });
  };
  closeModel = () => {
    this.setState({
      showAdd: false,
    });
  };
  onFinishAdd = async (e) => {
    console.log(e);
    this.setState({
      submitLoading: true,
    });
    await this.http("Admin", e, "POST");
    message.success("操作成功！");
    this.setState({
      submitLoading: false,
      showAdd: false,
    });
    this.props.refresh();
  };
  render() {
    return (
      <div>
        <Modal
          {...layout}
          title=""
          onCancel={this.closeModel}
          footer={[null, null]}
          visible={this.state.showAdd}
        >
          <Form name="add" onFinish={this.onFinishAdd}>
            <Form.Item
              label="管理员姓名"
              name="UserName"
              rules={[
                {
                  required: true,
                  message: "管理员姓名不可为空！",
                },
              ]}
            >
              <Input />
            </Form.Item>
            <Form.Item
              label="账号（手机号）"
              name="Phone"
              rules={[
                {
                  required: true,
                  message: "账号（手机号）不可为空！",
                },
              ]}
            >
              <Input />
            </Form.Item>
            <Form.Item
              label="密码"
              name="Password"
              rules={[
                {
                  required: true,
                  message: "密码不可为空！",
                },
              ]}
            >
              <Input />
            </Form.Item>
            <Form.Item {...tailLayout}>
              <Button
                loading={this.state.submitLoading}
                type="primary"
                htmlType="submit"
              >
                提交
              </Button>
            </Form.Item>
          </Form>
        </Modal>
        <Button type="primary" onClick={this.addMachineClick}>
          新增管理员
        </Button>
      </div>
    );
  }
}
